package serviceimpl;

import entity.Admin;
import entity.User;
import mapper.AdminMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import util.MD5Util;

@Service
public class AdminServiceImpl {
    @Autowired
    AdminMapper adminMapper;

    public String register(Admin admin){

        if(adminMapper.selectByUserName(admin.getAdminName())==null){
            adminMapper.insertSelective(admin);
            return "ok";
        }

        return "no";
    }


    public String login(String username,String password){
        Admin admin=adminMapper.selectByUserName(username);
        if(admin!=null){
            if(MD5Util.checkPassword(password,admin.getAdminPassword())){
                return "ok";//用户名密码都正确
            }else{
                return "no";//密码错误
            }
        }else{
            return "notExit";//用户名不存在
        }
    }

}
